import "./style.css";
import { createRoot } from "react-dom/client";
import App from "./App";
import Error from "./views/Error";
import Login from "./views/Login";
import Register from "./views/Register";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import { Toaster } from "react-hot-toast";

async function enableMocking() {
  if (process.env.CLIENT_ENV !== "local") {
    return;
  }
  const { worker } = await import("./mocks/browser.ts");
  return worker.start();
}

const root = createRoot(document.getElementById("root"));

enableMocking().then(() => {
  root.render(
    <>
      <Toaster />
      <Router>
        <Switch>
          <Route path="/login" exact>
            <Login />
          </Route>
          <Route path="/register" exact>
            <Register />
          </Route>
          <Route path="/" component={App} />
          <Route path="*" component={Error} />
        </Switch>
      </Router>
    </>
  );
});
